#include <iostream>

#include "redis_executor/redis_executor.h"
#include "redis_executor/scoped_reply.h"

using namespace std;

void * ThreadFun(void * data) {
  RedisExecutor * exec = (RedisExecutor *)data;

  for (int i = 0; i < 100000; ++i) {
    ScopedReply reply(exec->Execute("", "PING"));
    // ScopedReply reply(exec->Execute("", "SET "));
    if (reply) {
      cout << reply->str << endl;
    } else {
      cout << "connection error." << endl;
    }
  }

  return NULL;
}

int main() {
  RedisExecutor exec;

  const int kThreadCount = 20;
  pthread_t ts[kThreadCount];

  for (int i = 0; i < kThreadCount; ++i) {
    pthread_create(&ts[i], NULL, ThreadFun, &exec);
  }

  for (int i = 0; i < kThreadCount; ++i) {
    pthread_join(ts[i], NULL);
  }

  return 0;
}

